#pragma once

#include "Enums.h"
#include "Defines.h"
#include "SDL.h"
#include "SDL_image.h"


class cNonPlayer
{
private:
	int m_X;

	int m_Y;

	int m_SpeedX;

	SDL_Surface* m_Surf_Display;

	EntityType m_Type;

	int Delta;
public:

	cNonPlayer();
	cNonPlayer(int x, int y, EntityType Type, int delta):
	m_X(x),m_Y(y), m_Type(Type),Delta(delta)
	{
		m_SpeedX = NON_PLAYER_SPEED;
	}

	void OnLoad(SDL_Surface* Surf_Temp)
	{
		m_Surf_Display = SDL_DisplayFormatAlpha(Surf_Temp);
	}

	void Draw(SDL_Surface* Surf_Window, int X)
	{
		SDL_Rect source;
		SDL_Rect temp = {0, 0, NON_PLAYER_WIDTH,NON_PLAYER_HEIGHT};

		X = m_X;

		source = temp;
		SDL_Rect destination = {X, NON_PLAYER_Y, 
			NON_PLAYER_WIDTH,NON_PLAYER_HEIGHT};

		SDL_BlitSurface(m_Surf_Display, &source, Surf_Window, &destination);
	}

	void Move()
	{
		
		m_X += m_SpeedX;

		if(((m_SpeedX < 0) && CheckWall(LEFT)) ||
			((m_SpeedX > 0) && CheckWall(RIGHT)))
		{
			m_SpeedX = -m_SpeedX;
		}
	}

	bool CheckWall(Direction dir)
	{
		int temp_x;
	switch (dir)
	{
		case LEFT:
		{
			temp_x = m_X- NON_PLAYER_SPEED;
		} break;
		case RIGHT:
		{
			
			temp_x = m_X + NON_PLAYER_WIDTH + NON_PLAYER_SPEED;
		} break;
	}

	if (temp_x <= WINDOW_LIMIT_LEFT)
	{
			m_X = WINDOW_LIMIT_LEFT;
			return true;

	}else if (temp_x >= WINDOW_WIDTH)
	{
		m_X = WINDOW_WIDTH - NON_PLAYER_WIDTH;
		return true;
	}

	return false;
	}

	int Get_X(){return m_X;}
	int Get_Y(){return m_Y;}

	int GetSpeed_X(){return m_SpeedX;}
	void SetSpeed_X(int x){m_SpeedX = x;}

	void Set_X(int x){m_X = x;}
	void Set_Y(int y){m_Y = y;}

	int GetDelta(){return Delta;}
	void SetDelta(int x){Delta = x;}
};